package me.zhengjie.pm.taskassignment.domain;

import com.fasterxml.jackson.annotation.JsonIdentityInfo;
import com.fasterxml.jackson.annotation.ObjectIdGenerators;
import lombok.Data;
import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.bean.copier.CopyOptions;
import me.zhengjie.hr.employeebase.domain.EmployeeBase;
import me.zhengjie.pm.projectissue.domain.ProjectIssue;
import me.zhengjie.pm.projecttask.domain.ProjectTask;

import javax.persistence.*;
import javax.validation.constraints.*;
import java.io.Serializable;

/**
* @author yuxj
* @date 2020-04-14
*/
@Entity
@Data
@Table(name="staff_work_task")
@JsonIdentityInfo(generator = ObjectIdGenerators.PropertyGenerator.class, property = "id")
public class StaffWorkTask implements Serializable {

    /** ID */
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Column(name = "id")
    private Integer id;

    /** 工作分配人 */
    @Column(name = "assign_id")
    private Integer assignId;

    /** 工作执行人 */
    @Column(name = "worker_id")
    private Integer workerId;

    @OneToOne
    @JoinColumn(name = "worker_id", insertable = false, updatable = false, nullable=true)
    private EmployeeBase employeeBase;

    /** 任务ID */
    @Column(name = "task_id")
    private Integer taskId;
    @OneToOne
    @JoinColumn(name = "task_id", insertable = false, updatable = false, nullable=true)
    private ProjectTask projectTask;

    /** 问题ID */
    @Column(name = "issue_id")
    private Integer issueId;
    @OneToOne
    @JoinColumn(name = "issue_id", insertable = false, updatable = false, nullable=true)
    private ProjectIssue projectIssue;

    public void copy(StaffWorkTask source){
        BeanUtil.copyProperties(source,this, CopyOptions.create().setIgnoreNullValue(true));
    }
}